
//Page Script of FsCarInfo.FsCarInventory

//Show grid..
Ext.onReady(function () {
	var itemGrid = new FsCarInfo.FsCarInventory.GridPanel({
		tbarMask: '111111111',
		formSubmitUrl: '/FsCarInventory/SaveOrUpdate'
	});

	// selModel
	var selModel = new Ext.grid.CheckboxSelectionModel({
		//header: '',
		//singleSelect: true,
		menuDisabled: true,
		listeners: {
			'selectionchange': function (sm) {
				// 控制工具栏按钮是否可用
				sm.grid.saveButton.setDisabled(sm.getCount() < 1);
			}
		}
	});

	// columnModel 对于不常需要显示的 hidden: true 
	var gridColumn = new Ext.grid.ColumnModel({
		columns: [
				new Ext.grid.RowNumberer(),
				selModel,
				{ header: "盘点类型", dataIndex: 'Type',
					renderer: function (v) {
						return v == "" ? "v" : FsCarInfo.Params.InventoryTypeStore.getById(v).get('Name');
					}
				},
				{ header: "盘点日期", dataIndex: 'InveDate', xtype: 'datecolumn', format: 'Y年m月d日 H:i' },
				{ header: "盘点机构", dataIndex: 'Department.Name' },
				{ header: "复核用户ID", dataIndex: 'ReviUser.Name' },
				{ header: "状态", dataIndex: 'State',
					renderer: function (v) {
						return v == null ? "未知" : FsCarInfo.Params.InventoryStateStore.getById(v).get('Name');
					}
				}
			],
		defaults: {
			sortable: true,
			menuDisabled: false
		}
	});

	var myGrid = new Ext.grid.EditorGridPanel({
		title: 'My EditorGridPanel',
		store: itemGrid.store,
		sm : selModel,
		cm: gridColumn,
		tbar: new Ext.Toolbar({
			items :[{
				text: 'Save',
				//handler: saveChanges,
				disabled: true,
				ref: '../saveButton'
			}]
		}),
		listeners: {
			afteredit: function () {
				//  The button reference is in the GridPanel
				myGrid.saveButton.enable();
			}
		}
	});

	//加载
	JsHelper.ExtTabDoLayout(itemGrid);
	itemGrid.store.load({
		url: '/FsCarInventory/GetPlist',
		params: {
			start: 0,
			limit: ALL_PAGESIZE_SETTING
		}
	});
});